<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>Add Sale Lead | Merlion's ERP System</title>
    </ui:define>

    <ui:define name="content">
        <p:panel id="panel" header="Add New Sale Lead"> 
            <p:ajaxStatus style="width:16px;height:16px;">   
                <f:facet name="start">   
                    <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                </f:facet> 

                <f:facet name="complete">   
                    <h:outputText value="" />   
                </f:facet>   
            </p:ajaxStatus> 

            <p:messages /> 
            
            <h:form prependId="false">
                <p:fieldset legend="Company Details">
                <h:panelGrid columns="3" cellpadding="10"> 
                    
                    <h:outputLabel for="saleLeadName" style="font-weight: bold" value="Sale Lead Name: " /> 
                    <p:inputText value="#{saleLeadManagerBean.saleLeadName}" required="true" label="Sale Lead Name" requiredMessage="Sale Lead Name is required." id="saleLeadName"> 
                        
                    </p:inputText> 
                    <p:message for="saleLeadName" /> 
                    
                    <h:outputLabel for="registrationNumber" style="font-weight: bold" value="Registration Number: " /> 
                    <p:inputText label="registrationNumber" required="true" requiredMessage="Registration Number is required." id="registrationNumber" value="#{saleLeadManagerBean.registrationNumber}"> 
                        
                    </p:inputText> 
                    <p:message for="registrationNumber" /> 

                    <h:outputLabel for="address" style="font-weight: bold" value="Address: " /> 
                    <p:inputText label="address" required="true" requiredMessage="Address is required." id="address" value="#{saleLeadManagerBean.address}">                         
                    </p:inputText> 
                    <p:message for="address" /> 
                    
                    <h:outputLabel for="customerType" style="font-weight: bold" value="Customer Type: " /> 
                    <h:selectOneMenu id ="customerType" value="#{saleLeadManagerBean.customerType}">
                        <f:selectItem itemValue="WholeSale" itemLabel="Whole Sale" id="wholeSale" />
                        <f:selectItem itemValue="DirectSale" itemLabel="Direct Sale" id="directSale" />
                    </h:selectOneMenu>
                    
                    
                    <p:message for="customerType" />
                </h:panelGrid>
                </p:fieldset>
                <br/>
                <p:fieldset legend="Representative Details"> 
                    <p:commandButton value="Add New" onclick="addRepDialog.show()" ajax="true"/>  
                    <p:separator/>
                    <p:dataTable value="#{saleLeadManagerBean.reps}" var="rep" id="repTable">
                        <p:column sortBy="#{rep.name}" style="width: 30%"> 
                            <f:facet name="header"> 
                                <h:outputText value="Representative Name" /> 
                            </f:facet> 
                            <h:outputText value="#{rep.name}" /> 
                        </p:column>

                        <p:column sortBy="#{rep.email}" style="width: 40%"> 
                            <f:facet name="header"> 
                                <h:outputText value="Email" /> 
                            </f:facet> 
                            <h:outputText value="#{rep.email}" /> 
                        </p:column>

                        <p:column sortBy="#{rep.contactNumber}" style="width: 30%"> 
                            <f:facet name="header"> 
                                <h:outputText value="Contact Number" /> 
                            </f:facet> 
                            <h:outputText value="#{rep.contactNumber}" /> 
                        </p:column>
                    </p:dataTable>
                </p:fieldset>
                <br/>    
                <p:commandButton id="btn" value="Save New Sale Lead" update="panel" actionListener="#{saleLeadManagerBean.saveNewSaleLead}" ajax="true"/>
            </h:form>
            <h:form>      
                <p:dialog header="Representative Detail" widgetVar="addRepDialog" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display3" columns="2">
                        <h:outputText value="Representative Name:" style="font-weight: bold"/>
                        <p:inputText value="#{saleLeadManagerBean.newRep.name}" required="true" requiredMessage="Representative Name is required"/>
                        <h:outputText value="Representative Email:" style="font-weight: bold"/>
                        <p:inputText value="#{saleLeadManagerBean.newRep.email}" required="true" requiredMessage="Representative Email is required"/>
                        <h:outputText value="Representative Contact Number: " style="font-weight: bold"/>
                        <p:inputText value="#{saleLeadManagerBean.newRep.contactNumber}" required="true" requiredMessage="Representative Contact Number is required"/>
                        <p:commandButton value="Add" actionListener="#{saleLeadManagerBean.addRep}" update="repTable display3" oncomplete="addRepDialog.hide()"/>  
                    </h:panelGrid>
                </p:dialog>
            </h:form>
        </p:panel>
    </ui:define>

</ui:composition>
